package com.springstudy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

//不能使用@EnableWebMvc
//声明该类为配置类
@Configuration
//必须实现WebMvcConfigurer
public class MyMvcConfig implements WebMvcConfigurer {
    //重写视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        //视图链接为mvc时跳转到thymeleafPath.html页面
        registry.addViewController("mvc").setViewName("thymeleafPath");
    }


    //重写跨域请求拦截等

    //在Config中调用自定义配置
    @Bean
    public ViewResolver myViewResolver(){
        return new MyViewResolver();
    }

    //实现了ViewResolver视图解析器接口的类，我们就可以把它看做视图解析器
    //自定义视图解析器
    public static class MyViewResolver implements ViewResolver {
        @Override
        public View resolveViewName(String s, Locale locale) throws Exception {
            return null;
        }
    }
}